package com.jinxin.platform.cdysylives.controller;

import com.jinxin.platform.base.api.annotation.*;
import com.jinxin.platform.base.api.constant.APCOSApiConstans;
import com.jinxin.platform.base.common.annotation.UnLoginForUser;
import com.jinxin.platform.cdysylives.bean.bo.AppKeySecretInfo;
import com.jinxin.platform.cdysylives.common.ResultEntity;
import com.jinxin.platform.cdysylives.service.IAccesstokenService;
import com.jinxin.platform.cdysylives.service.IEquipmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-03-12
 * @Author: Lingnan
 **/
@APCOSApi(value = "萤石云接口", developers = {"那个男人"}, description = "萤石云接口")
@RestController
@RequestMapping("/cdysylives")
@Slf4j
public class YsyController {
    @Autowired
    private IAccesstokenService accesstokenService;
    @Autowired
    private IEquipmentService equipmentService;

    @UnLoginForUser
    @APCOSApiOperation(value = "保存或更新应用秘钥信息", developers = {"lingnan"}, description = "保存或更新应用秘钥信息",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @PostMapping("/saveAkInfo")
    public ResultEntity saveAkInfo(AppKeySecretInfo appKeySecretInfo){
        return accesstokenService.saveOrUpdateKey(appKeySecretInfo);
    }

    @UnLoginForUser
    @APCOSApiOperation(value = "获取应用秘钥信息", developers = {"lingnan"}, description = "获取应用秘钥信息",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/getAkInfoByUser")
    public ResultEntity getAkInfoByUser(){
        return accesstokenService.getAkInfoByUser();
    }

    @UnLoginForUser
    @APCOSApiOperation(value = "获取设备列表", developers = {"lingnan"}, description = "获取设备列表",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @APCOSApiRequests({})
    @APCOSApiResponses({
            @APCOSApiResponse(name = "code", value = "状态码0成功", required = true, fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM, lenth = "5,0"),
            @APCOSApiResponse(name = "msg", value = "提示信息", required = true, fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR, lenth = "100"),
            @APCOSApiResponse(name = "data", value = "返回的设备列表", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_ARR),
            @APCOSApiResponse(name = "data.deviceSerial", value = "设备序列号", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "30"),
            @APCOSApiResponse(name = "data.deviceName", value = "设备名称", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.deviceType", value = "设备类型", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.status", value = "在线状态0-不在线,1-在线", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "1,0"),
            @APCOSApiResponse(name = "data.defence", value = "具有防护能力的设备布撤防状态0-睡眠，8-在家，16-外出，普通IPC布撤防状态：0-撤防，1-布防", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "10,0"),
            @APCOSApiResponse(name = "data.deviceVersion", value = "设备版本号", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.addTime", value = "添加时间", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "20,0"),
            @APCOSApiResponse(name = "data.updateTime", value = "更新时间", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "20,0"),
            @APCOSApiResponse(name = "data.parentCategory", value = "分类", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "10,0"),
            @APCOSApiResponse(name = "data.count", value = "设备数量", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "10,0"),
    })
    @GetMapping("/listDevice")
    public Map<String,Object> listDevice(){
        return equipmentService.listDevices();
    }

    @UnLoginForUser
    @APCOSApiOperation(value = "获取播放地址", developers = {"lingnan"}, description = "获取播放地址",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @APCOSApiRequests({
            @APCOSApiRequest(name = "deviceSerial",value = "设备序列号",required = true,fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    reqType = APCOSApiConstans.REQ_TYPE_PATH,dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "32",matchType = APCOSApiConstans.MATCH_TYPE_EQ),
            @APCOSApiRequest(name = "quality",value = "视频清晰度1-高清(主码流)2-流畅(子码流)",fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    reqType = APCOSApiConstans.REQ_TYPE_PATH,dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "10",matchType = APCOSApiConstans.MATCH_TYPE_EQ),
            @APCOSApiRequest(name = "channelNo",value = "通道号",required = true,fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    reqType = APCOSApiConstans.REQ_TYPE_PATH,dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "10",matchType = APCOSApiConstans.MATCH_TYPE_EQ),
    })
    @APCOSApiResponses({
            @APCOSApiResponse(name = "resultCode", value = "状态码000成功", required = true, fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM, lenth = "5,0"),
            @APCOSApiResponse(name = "resultDesc", value = "提示信息", required = true, fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR, lenth = "100"),
            @APCOSApiResponse(name = "resultContent", value = "返回信息", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_OBJ),
            @APCOSApiResponse(name = "resultContent.token", value = "token", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "resultContent.url", value = "播放地址", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "2000"),
    })
    @GetMapping("/getLiveAddress")
    public ResultEntity getLiveAddress(String deviceSerial,String quality,String channelNo){
        return equipmentService.getVideoAddress(deviceSerial,quality,channelNo);
    }

    @UnLoginForUser
    @APCOSApiOperation(value = "获取指定设备的通道信息", developers = {"lingnan"}, description = "获取指定设备的通道信息",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @APCOSApiRequests({
            @APCOSApiRequest(name = "deviceSerial",value = "设备序列号",required = true,fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    reqType = APCOSApiConstans.REQ_TYPE_PATH,dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "32",matchType = APCOSApiConstans.MATCH_TYPE_EQ),
    })
    @APCOSApiResponses({
            @APCOSApiResponse(name = "code", value = "状态码0成功", required = true, fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM, lenth = "5,0"),
            @APCOSApiResponse(name = "msg", value = "提示信息", required = true, fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR, lenth = "100"),
            @APCOSApiResponse(name = "data", value = "返回的通道列表", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_ARR),
            @APCOSApiResponse(name = "data.deviceSerial", value = "设备序列号", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.ipcSerial", value = "IPC序列号", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.channelNo", value = "通道号", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.deviceName", value = "设备名", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.localName", value = "设备上报名称", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.channelName", value = "通道名", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.picUrl", value = "图片地址（大图），若在萤石客户端设置封面则返回封面图片，未设置则返回默认图片", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "2000"),
            @APCOSApiResponse(name = "data.isEncrypt", value = "是否加密,0不加密,1加密", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "1,0"),
            @APCOSApiResponse(name = "data.videoLevel", value = "视频质量:0-流畅,1-均衡,2-高清,3-超清", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "1,0"),
            @APCOSApiResponse(name = "data.relatedIpc", value = "当前通道是否关联IPC：true-是，false-否。设备未上报或者未关联都是false", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "10"),
            @APCOSApiResponse(name = "data.isAdd", value = "0:隐藏，1:显示", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "1,0"),
            @APCOSApiResponse(name = "data.count", value = "通道数量", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "10,0"),
    })
    @GetMapping("/listChannelByDevice")
    public Map<String,Object> listChannelByDevice(@RequestParam(name = "deviceSerial") String deviceSerial){
        return equipmentService.listChannelByDevice(deviceSerial);
    }

    @UnLoginForUser
    @APCOSApiOperation(value = "获取摄像头列表", developers = {"lingnan"}, description = "获取摄像头列表",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @APCOSApiRequests({
            @APCOSApiRequest(name = "page",value = "页码",required = true,fieldType = APCOSApiConstans.FIELD_TYPE_GN,
            reqType = APCOSApiConstans.REQ_TYPE_PATH,dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "10",matchType = APCOSApiConstans.MATCH_TYPE_EQ),
            @APCOSApiRequest(name = "limit",value = "每页条数,默认为10,最大为50",required = true,fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    reqType = APCOSApiConstans.REQ_TYPE_PATH,dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "10",matchType = APCOSApiConstans.MATCH_TYPE_EQ),
    })
    @APCOSApiResponses({
            @APCOSApiResponse(name = "code", value = "状态码0成功", required = true, fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM, lenth = "5,0"),
            @APCOSApiResponse(name = "msg", value = "提示信息", required = true, fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR, lenth = "100"),
            @APCOSApiResponse(name = "data", value = "返回的设备列表", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_ARR),
            @APCOSApiResponse(name = "data.id", value = "摄像头id", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.deviceSerial", value = "设备序列号", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.channelNo", value = "通道号", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "50"),
            @APCOSApiResponse(name = "data.status", value = "在线状态0-不在线,1-在线", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "1,0"),
            @APCOSApiResponse(name = "data.isShared", value = "是否分享?", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "10,0"),
            @APCOSApiResponse(name = "data.picUrl", value = "图片地址（大图），若在萤石客户端设置封面则返回封面图片，未设置则返回默认图片", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_STR,lenth = "2000"),
            @APCOSApiResponse(name = "data.isEncrypt", value = "是否加密,0不加密,1加密", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "1,0"),
            @APCOSApiResponse(name = "data.videoLevel", value = "视频质量:0-流畅,1-均衡,2-高清,3-超清", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "1,0"),
            @APCOSApiResponse(name = "data.permission", value = "分享设备的权限字段", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "1,0"),
            @APCOSApiResponse(name = "data.isAdd", value = "0:隐藏，1:显示", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "1,0"),
            @APCOSApiResponse(name = "data.count", value = "设备数量", fieldType = APCOSApiConstans.FIELD_TYPE_GN,
                    dataType = APCOSApiConstans.DATA_TYPE_NUM,lenth = "10,0"),
    })
    @GetMapping("/listCamera")
    public Map<String,Object> listCamera(@RequestParam(name = "page") Integer page, @RequestParam(name = "limit") Integer limit){
        return equipmentService.listCam(page,limit);
    }
}
